package springboot1706.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import springboot1706.bean.Goods;
import springboot1706.service.impl.GoodsServiceImpl;

@Controller
@RequestMapping("/good")
public class GoodsController {
	
	Logger log = LoggerFactory.getLogger(TestController.class);
      @Autowired
      private GoodsServiceImpl goodsServiceImpl;
      
      
  	@RequestMapping("/index")
  	public String index(){
  		return "index";
  	} 
  	/**
  	 * 根据id查询是商品详情
  	 * @param request
  	 * @return
  	 */
  	@RequestMapping("/det")
  	public String det(HttpServletRequest request,HttpSession session,@RequestParam(value="id") String id){
  		log.debug("传输过来的数据"+id);
  		Goods goods=new Goods();
  		goods.setId(id);
  		List<Goods> list=goodsServiceImpl.getGoodById(goods);
        for(int i=0;i<list.size();i++) {
        	Goods gd = list.get(i);
            if(gd.getGstatus()==0) {
        	   return "xiajia";
         }else {
        	 session.setAttribute("list", list);
       		 return "detail";
         }
            
       }
        return "detail";
	    
  		
  	}
	

  

  	
  	
  	/**
  	 * 搜索
  	 * @return
  	 */
  	@RequestMapping("/fuzzy")
  	public String fuzzy(HttpServletRequest request){
  		String goods=request.getParameter("goods");
  		List<Goods> listgoods=goodsServiceImpl.getGoodByName(goods);
  		request.getSession().setAttribute("listgoods", listgoods);
  		return "search";
  	}
  	/**
  	 * 查询所有商品
  	 * @param request
  	 * @return
  	 */
  	@RequestMapping("/all")
  	public String all(HttpServletRequest request){
  		String goods=request.getParameter("goods");
  		List<Goods> listgoods=goodsServiceImpl.getAll();
  		request.getSession().setAttribute("listgoods", listgoods);
  		return "all";
  	}

  	
  	
  	
  	
  }
